<!-- 新增、编辑 -->

<template>
  <el-dialog
    :model-value="dialogFormVisible"
    :destroy-on-close="true"
    title="版本信息"
    width="550px"
    @close="emits('closeDialog')"
  >
    <el-form ref="dialogFormRef" :model="dialogForm">
      <el-form-item label="更新渠道" :label-width="formLabelWidth">
        <el-select v-model="dialogForm.platform" placeholder="更新渠道">
            <el-option label="Google Play" value="google" />
            <el-option label="Metafun官网APK" value="metafun" />
            <el-option label="Apple AppStore" value="appstore" />
        </el-select>
      </el-form-item>
      <el-form-item label="版本号" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.version" />
      </el-form-item>
      <el-form-item label="更新内容" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.version_log" :rows="2" type="textarea" />
      </el-form-item>
      <el-form-item label="更新日期" :label-width="formLabelWidth">
        
        <el-date-picker
          v-model="dialogForm.update_date"
          type="date"
          placeholder="更新日期"
          value-format="YYYY-MM-DD"
        />
      </el-form-item>
      <el-form-item label="包大小" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.size" />
      </el-form-item>

      <el-form-item label="版本code" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.version_code" />
      </el-form-item>
      <el-form-item label="最小code" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.min_code" />
      </el-form-item>
      <el-form-item label="最大code" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.max_code" />
      </el-form-item>
      <el-form-item label="是否强制更新" :label-width="formLabelWidth">
        <el-select v-model="dialogForm.is_force" placeholder="是否强制更新">
          <el-option label="否" :value="0" />
          <el-option label="是" :value="1" />
        </el-select>
      </el-form-item>
      <el-form-item label="apk包更新url" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.apk_url" />
      </el-form-item>
      <el-form-item label="GooglePlay下载地址" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.google_play_url" />
      </el-form-item>
      <el-form-item label="AppStore下载地址" :label-width="formLabelWidth">
        <el-input v-model="dialogForm.app_store_url" />
      </el-form-item>
      <el-form-item label="版本ID" style="display: none">
        <el-input v-model="dialogForm.upgrade_id" disabled />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="emits('cancel')">取消</el-button>
        <el-button
          type="primary"
          @click="submit(dialogForm)"
          :loading="btnLoading"
        >
          提交
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref } from "vue";

const dialogFormRef = ref(null);

defineProps({
  dialogFormVisible: {
    type: Boolean,
    default: false,
  },
  dialogForm: {
    type: Object,
    default: {
      upgrade_id: "",
      platform: "",
      version: "",
      version_log: "",
      update_date: "",
      size: "",
      version_code: "",
      min_code: "",
      max_code: "",
      is_force: "",
      apk_url: "",
      google_play_url: "",
      app_store_url: "",
    },
  },
  btnLoading: {
    type: Boolean,
    default: false,
  },
});
const emits = defineEmits(["closeDialog", "cancel", "submitForm"]);

const formLabelWidth = "180px";

// 提交
const submit = (dialogForm) => {
  dialogFormRef.value
    .validate()
    .then(async () => {
      try {
        delete dialogForm.id;
        dialogForm.is_force = Number(dialogForm.is_force);
        emits("submitForm", dialogForm);
      } catch (error) {
        console.log(error);
      }
    })
    .catch((error) => {
      console.log(error);
    });
};
</script>
